package com.panda.springcloud.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panda.springcloud.clients.TagClient;
import com.panda.springcloud.entity.Clazz;
import com.panda.springcloud.entity.Tag;
import com.panda.springcloud.service.ClazzService;
import com.panda.springcloud.mapper.ClazzMapper;
import com.panda.springcloud.vo.ClazzVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 乐于吕
 * @description 针对表【t_clazz】的数据库操作Service实现
 * @createDate 2024-10-23 11:08:38
 */
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz>
        implements ClazzService {

    @Autowired
    private TagClient tagClient;

    @Override
    public List<ClazzVO> clazzList() {
        List<Clazz> clazzes = baseMapper.selectList(null);

        // 遍历班级列表
        List<ClazzVO> collect = clazzes.stream().map(clazz -> {
            ClazzVO clazzVO = new ClazzVO();
            BeanUtils.copyProperties(clazz, clazzVO);
            Integer tagId = clazz.getTagid();
            // 根据班级的tagId  查询标签服务   openfeign
            Tag tag = tagClient.getTagById(tagId);
            clazzVO.setTag(tag);
            return clazzVO;
        }).collect(Collectors.toList());

        return collect;
    }

}




